package com.xinqi.modules.user.users.user.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.user.user.dto.req.UserExtendCreateDTO;
import com.xinqi.modules.user.user.dto.req.UserExtendQueryDTO;
import com.xinqi.modules.user.user.dto.req.UserExtendUpdateDTO;
import com.xinqi.modules.user.user.dto.rsp.UserExtendResultDTO;
import com.xinqi.modules.user.users.user.service.UserExtendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 用户扩展信息APP控制层
 *
 * @author: wenjie
 * @date: 2023/05/17
 */
@Tag(name = "App-用户扩展信息", description = "用户扩展信息App接口")
@RestController
@RequestMapping("/app/user-extend")
@RequiredArgsConstructor
public class UserExtendAppController {
    private final UserExtendService userExtendService;

    /**
     * 用户扩展信息-分页
     */
    @Operation(summary = "用户扩展信息-分页")
    @GetMapping("/page")
    public R<PageInfo<UserExtendResultDTO>> page(@ParameterObject UserExtendQueryDTO dto) {
        PageInfo<UserExtendResultDTO> page = userExtendService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 用户扩展信息-详情
     */
    @Operation(summary = "用户扩展信息-详情")
    @GetMapping("/{id}")
    public R<UserExtendResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        UserExtendResultDTO dto = userExtendService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增用户扩展信息
     */
    @Operation(summary = "新增用户扩展信息")
    @PostMapping
    public R<Long> insert(@RequestBody UserExtendCreateDTO dto) {
        return R.data(userExtendService.insert(dto));
    }

    /**
     * 修改用户扩展信息
     */
    @Operation(summary = "修改用户扩展信息")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody UserExtendUpdateDTO dto) {
        dto.setId(id);
        return R.data(userExtendService.updateById(dto));
    }

    /**
     * 删除用户扩展信息
     */
    @Operation(summary = "删除用户扩展信息")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(userExtendService.deleteById(id));
    }
}
